package com.mcintyret.site.utils;

import com.google.common.collect.Iterables;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mcintyret.site.journal.Timeseries;
import org.springframework.stereotype.Component;

/**
 * User: mcintyret2
 * Date: 05/04/2012
 */

@Component
public class TimeseriesGson {

    private final static Gson GSON = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation().create();

    public String toJson(Timeseries timeseries) {
        return toJson(new Timeseries[]{timeseries});
    }

    public String toJson(Timeseries[] timeseries) {
        return GSON.toJson(timeseries);
    }

    public String toJson(Iterable<Timeseries> timeseries) {
        return toJson(Iterables.toArray(timeseries, Timeseries.class));
    }
}
